import { Component, OnInit } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd';
import { ApiService } from 'src/app/core/api';
import { MessageService } from 'src/app/core/service/message.service';
import { FormBuilder, Validators } from '@angular/forms';
import {DatePipe} from '@angular/common';
import { Router } from '@angular/router';
import { I18nService } from 'src/app/core/i18n/i18n.service';

@Component({
    templateUrl: './index.html',
    providers: [DatePipe]
})
export class TravelAgencyComponent implements OnInit {
	page: any = {
		pageNo: 1,
		areaId:''
	};
	areaList = [];
	dateRange;
	dataList = [];
	isVisible = false;
	tableLoading = false;
	modalTitle;
	selectedRowData: any = {};
	validateForm;
	language = {};
	constructor(
        private apiService: ApiService,
        private nzMessageService: NzMessageService,
        private message: MessageService,
        private fb: FormBuilder,
		private datepipe: DatePipe,
		private router: Router,
		private i18n:I18nService
        ) {
			this.i18n.get(["placeholder",'pagetitle']).subscribe(res=>{
				this.language = res.placeholder;
				const pagetitle = res.pagetitle;
				this.message.setBreadcrumb({
					breadcrumbs: [{ name: pagetitle.title1}],
				});
			})
        }
	ngOnInit() {
		this.apiService.post('地区列表(用于选择框)', {}).then((res: any) => {
			this.areaList = res.data.list;
			this.page.pageNo = res.data.pageNo;
            this.page.pages = res.data.pages * 10;
			this.tableLoading = false;
		});
		this.loadList();
	}
	changeCurrentPage(e) {
        if (e) {
            this.page.pageNo = e;
            this.loadList();
        }
	}
	loadList() {
		this.tableLoading = true;
		this.apiService.post('旅行社列表', { ...this.page }).then((res: any) => {
			this.dataList = res.data.list;
			this.page.pageNo = res.data.pageNo;
            this.page.pages = res.data.pages * 10;
			this.tableLoading = false;
		});
	}
	onChange(date) {
		if (date.length > 0) {
			this.page.beginTime = this.datepipe.transform(date[0],'yyyy-MM-dd');
			this.page.endTime = this.datepipe.transform(date[1],'yyyy-MM-dd');
		} else {
			this.page.beginTime = '';
			this.page.endTime = '';
		}
	}
	searchList() {
		this.page.pageNo = 1;
		this.loadList();
	}
}
